
$(function(){
    $("#home1").bind("tap",toHome);
    $("#home2").bind("tap",toHome);
	$("#login").bind("tap",function(){
			  //表单校验
			   var checked=$("#loginform").check();
			   if(checked){
					var params = {};
				   var LoginMsg="";
					params.j_username = $("#login_name").val(); 
					params.j_password = $("#login_pwd").val();
					
										//登陆
					 Newtouch.Ajax.sendParams(params,localStorage['APP_AJAX_PATH']+"/drinkingBar/view/login.jsp.userLogin",function(){
						 $(window).mobileMsgBox({msgText:"登陆成功！",delayTime:2000});
						 androidLocal({"username":params.j_username});// 本地存储登录信息
							window.location="main.html";
					 },function(err){
				      		$(window).mobileMsgBox({msgText:"用户名/密码错误！",delayTime:2000});
				      	});
			   }
		
	});
	
	$("#sendForm").bind("tap",function(){
		var checked=$("#loginzhuce").check();
		if(checked){
		  var values=$("#loginzhuce").values();
		  Newtouch.Ajax.sendParams(values,localStorage['APP_AJAX_PATH']+"/drinkingBar/view/login.jsp.registerUser",function(){
          	$(window).mobileMsgBox({msgText:"注册成功，自动跳转至首页！",delayTime:2000});
          	var params = {};
			params.j_username = $("#name").val(); 
			params.j_password = $("#newPassword").val();
          Newtouch.Ajax.sendParams(params,localStorage['APP_AJAX_PATH']+"/drinkingBar/view/login.jsp.userLogin",function(){
						 $(window).mobileMsgBox({msgText:"登陆成功！",delayTime:2000});
						 androidLocal({"username":params.j_username});// 本地存储登录信息
							window.location="main.html";
					 },function(err){
				      		$(window).mobileMsgBox({msgText:"用户名/密码错误！",delayTime:2000});
      	});
			});	
		}
		


	
});
});
	var androidLocal=function(p){
		sessionStorage.clear(); //清空已有记录，保存新纪录
		for(var k in p){
			sessionStorage[k]=p[k];
		}
		
	}
function toHome(){
	window.location = "main.html";
}

	
	
